package com.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Create with Intellij idea
 * User:鲁智明
 * Date:2018/9/19
 * Time:22:05
 */
@RestController
public class CookieController {

    private Cookie[] cookies;

    @RequestMapping("/addCookie")
    public String addCookied(HttpServletRequest request, HttpServletResponse response) {
        Cookie cookie = new Cookie("idea", "idea2018.1");
        response.addCookie(cookie);
        return "添加Cookie成功";
    }

    @RequestMapping("/getCookie")
    public Cookie[] getCookie(HttpServletRequest request, HttpServletResponse response) {
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            System.out.println(cookie.getName() + "---" + cookie.getValue());
        }

        return cookies;

    }
}
